/**
 * @file
 * @author
 * @date
 * @brief 睡眠算法
 */
#ifndef SLEEP_ALGORITHM_H_
#define SLEEP_ALGORITHM_H_
#include "stdint.h"
#define MINUTE_PER_DAY (1440)
#define SLEEP_MASTER_SECTION_TIME_START_MINUTE (25 * 60) //主睡眠起始时间-分-第二天早上2点
#define SLEEP_MASTER_SECTION_TIME_END_MINUTE (7 * 60)    //主睡眠结束时间-分

#define SLEEP_NIGHT_START_MINUTE (23 * 60) //夜间
#define SLEEP_NIGHT_END_MINUTE (7 * 60)
#define SLEEP_MASTER_CALC_SEARCH_BOUNDARY_MINUTE (18 * 60) //主睡眠搜索算法的边界时间点

typedef enum
{
    FLASH_MODIFY_SLEEP_INTO,        //睡眠入睡
    FLASH_MODIFY_SLEEP_TO_DROPOFF,  //睡眠转摘下
    FLASH_MODIFY_SLEEP_TO_MOVEMENT, //睡眠转运动
} flash_modify_type_t;

typedef enum
{
    SLEEP_STATUS_STANDBY = 0,  //空状态
    SLEEP_STATUS_MOVEMENT = 1, //未入睡
    SLEEP_STATUS_SLEEPING,     //浅睡
    SLEEP_STATUS_DROPOFF,      //摘下
    SLEEP_STATUS_AWAKE,        //清醒
} sleep_status_t;

void sleep_algorithm_init(void);
sleep_status_t sleep_algorithm_drv(void);
void sleep_active_add_handle(uint8_t active_add);
void sleep_hand_change_handle(uint8_t hand_change);

#define SLEEP_DATA_OUT_GROUP_MAX (40) //睡眠数据输出组数
#define SLEEP_DATA_OUT_MAX (24)       //最大运动量--函数内将*p_result最大值定义为这个值
#define SLEEP_TIME_LITTLE_MAX_TIME (15 * 60) //睡眠时间最大值
void sleep_algorithm_reset(void);
uint16_t sleep_algorithm_get_sleeptime_wait_store(void);
uint16_t sleep_algorithm_get_sleeptime_wait_store_sub(void);
uint16_t sleep_algorithm_get_sleep_minute(void);
uint16_t sleep_algorithm_get_awake_continue_time(void);
void sleep_debug_info_clear(void);
void sleep_algorithm_clear_master_time(void);
void sleep_algorithm_master_time_search_flash(void);
void sleep_algorithm_master_sleep_quality_calc(void);
uint8_t sleep_algorithm_get_master_sleep_quality(uint16_t *start_min, uint16_t *end_min, uint8_t *p_result);

int sleep_test_data_get(uint8_t *p_dst_buff, int offset, int max_len);
void sleep_test_data_clear(void);
void sleep_test_data_save(void);
sleep_status_t sleep_algorithm_state(void);
#endif
